 <template>
  <el-container style="height: 100vh; border: 1px solid #eee">
    <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
      <el-menu router :default-openeds="['1']">
        <el-submenu index="1">
          <template slot="title"
            ><i class="el-icon-tickets"></i>内容管理</template
          >
          <el-menu-item index="/articles/index">文章列表</el-menu-item>
          <el-menu-item index="/articles/create">新建文章</el-menu-item>
          <el-menu-item @click="logout">退出</el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      // 总条数，根据接口获取数据长度(注意：这里不能为空)
      totalCount: 0,
      pageSize: 0,
      list: [],
    };
  },
  methods: {
    logout() {
      window.localStorage.clear();
      this.$router.push("/login")
    },
    async save() {
      const res = await this.$http.get("/indexx");
      this.list = res.data.bloglist;
      this.totalCount = res.data.count;
      this.pageSize = res.data.pagesize;
      console.log(res.data);
    },
    async page(val) {
      const res = await this.$http.get(`indexx/?page=${val}`);
      console.log(res);
      this.list = res.data.bloglist;
      console.log(val);
      this.totalCount = res.data.count;
    },
    async open(item) {
      console.log(item);
      this.$confirm(
        "此操作将永久删除" + item.row.title + ", 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          const res = this.$http.post(`article/delete?id=${item.row.id}`);
          console.log(res);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.save();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },

  created() {
    this.save();
  },
};
</script>
<style>
.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-card {
  width: 480px;
}
</style>